/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package x.minigame1;
import java.awt.Graphics2D;
import java.awt.Image;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.imageio.IIOException;
import x.minigame1.level;



/**
 *
 * @author Omar
 */
public class bottle {
// x and y in terms of the grid
        private int x = 0;
        private int y = 0;
        /** The image to draw for this entity */
        public Image bottle;
        public level level;
        private URL bottleurl;

//these are the actual x and y coordinates
        public int relativex;
        public int relativey;

       public boolean activated;

   public bottle(level level, int x, int y) {

       //the default action of a new bottle is to deactivate it
       activated = true;


        //load the bottle image to memory
        bottleurl = Thread.currentThread().getContextClassLoader().getResource("minigame1/bottle.png");
try {bottle = ImageIO.read(bottleurl); }
    catch(Exception d){System.out.println("Error loading image: " + d);}

        //set some instance variables equal
                this.bottle = bottle;
                this.level = level;
                this.x = x;
                this.y = y;

        }



   public void start(Graphics2D g)
          {
          activated = true;
          paint(g);
          try{Thread.sleep(10000);}catch (Exception e){};
          activated = false;
          }


        public void paint(Graphics2D g) {
            if (activated == true)
            {
                relativex = (level.TILE_SIZE * x); //+100
                relativey = (level.TILE_SIZE * y); //+100
                g.drawImage(bottle, x * 10, y * 10, null);
            }

        }


public boolean checkHit(int mouseX, int mouseY){

  
//if the image is clicked, deactivate the bottle and then return true to add to score
if(mouseX >= relativex && mouseX < relativex+bottle.getWidth(null) 
   && mouseY >= relativey && mouseY < relativey+bottle.getHeight(null) && activated == true)
    {
activated = false;
return true;
    }
else
{
return false;
}
}

public void setLocation(int x2, int y2){
    x = x2;
    y = y2;
}


//activate and display the bottle
public void activate(){
    activated = true;
}

public void deactivate()
    {
    activated = false;
}

public void status(){
    System.out.println(activated);
}

}
